#ifndef _INTERRUPTS_H_
#define _INTERRUPTS_H_
#include <irq.h>

#define Swi_Touch_Screen_Handle()   do {\
        __asm__ __volatile__ (\
            "swi 0x1\n"\
        );} while(0)

#define IRQ_EINT0       (0)
#define IRQ_EINT1       (1)
#define IRQ_EINT2       (2)
#define IRQ_EINT3       (3)
#define IRQ_EINT4_7     (4)
#define IRQ_EINT8_23    (5)
#define IRQ_CAM         (6)
#define IRQ_BAT_FLT     (7)
#define IRQ_TICK        (8)
#define IRQ_WDT_AC97    (9)
#define IRQ_TIMER0      (10)
#define IRQ_TIMER1      (11)
#define IRQ_TIMER2      (12)
#define IRQ_TIMER3      (13)
#define IRQ_TIMER4      (14)
#define IRQ_UART2       (15)
#define IRQ_LCD         (16)
#define IRQ_DMA0        (17)
#define IRQ_DMA1        (18)
#define IRQ_DMA2        (19)
#define IRQ_DMA3        (20)
#define IRQ_SDI         (21)
#define IRQ_SPI0        (22)
#define IRQ_UART1       (23)
#define IRQ_NFCON       (24)
#define IRQ_USBD        (25)
#define IRQ_USBH        (26)
#define IRQ_IIC         (27)
#define IRQ_UART0       (28)
#define IRQ_SPI1        (29)
#define IRQ_RTC         (30)
#define IRQ_ADC         (31)
#define IRQ_MAX         (32)

#define _ISR_STARTADDRESS   0x33ffff00
// Exception vector
#define pISR_RESET      (*(unsigned *)(_ISR_STARTADDRESS+0x0))
#define pISR_UNDEF      (*(unsigned *)(_ISR_STARTADDRESS+0x4))
#define pISR_SWI        (*(unsigned *)(_ISR_STARTADDRESS+0x8))
#define pISR_PABORT     (*(unsigned *)(_ISR_STARTADDRESS+0xc))
#define pISR_DABORT     (*(unsigned *)(_ISR_STARTADDRESS+0x10))
#define pISR_RESERVED   (*(unsigned *)(_ISR_STARTADDRESS+0x14))
#define pISR_IRQ        (*(unsigned *)(_ISR_STARTADDRESS+0x18))
#define pISR_FIQ        (*(unsigned *)(_ISR_STARTADDRESS+0x1c))
// Interrupt vector
#define pISR_EINT0      (*(unsigned *)(_ISR_STARTADDRESS+0x20))
#define pISR_EINT1      (*(unsigned *)(_ISR_STARTADDRESS+0x24))
#define pISR_EINT2      (*(unsigned *)(_ISR_STARTADDRESS+0x28))
#define pISR_EINT3      (*(unsigned *)(_ISR_STARTADDRESS+0x2c))
#define pISR_EINT4_7    (*(unsigned *)(_ISR_STARTADDRESS+0x30))
#define pISR_EINT8_23   (*(unsigned *)(_ISR_STARTADDRESS+0x34))
#define pISR_CAM        (*(unsigned *)(_ISR_STARTADDRESS+0x38))     // Added for 2440.
#define pISR_BAT_FLT    (*(unsigned *)(_ISR_STARTADDRESS+0x3c))
#define pISR_TICK       (*(unsigned *)(_ISR_STARTADDRESS+0x40))
#define pISR_WDT_AC97       (*(unsigned *)(_ISR_STARTADDRESS+0x44))   //Changed to pISR_WDT_AC97 for 2440A 
#define pISR_TIMER0     (*(unsigned *)(_ISR_STARTADDRESS+0x48))
#define pISR_TIMER1     (*(unsigned *)(_ISR_STARTADDRESS+0x4c))
#define pISR_TIMER2     (*(unsigned *)(_ISR_STARTADDRESS+0x50))
#define pISR_TIMER3     (*(unsigned *)(_ISR_STARTADDRESS+0x54))
#define pISR_TIMER4     (*(unsigned *)(_ISR_STARTADDRESS+0x58))
#define pISR_UART2      (*(unsigned *)(_ISR_STARTADDRESS+0x5c))
#define pISR_LCD        (*(unsigned *)(_ISR_STARTADDRESS+0x60))
#define pISR_DMA0       (*(unsigned *)(_ISR_STARTADDRESS+0x64))
#define pISR_DMA1       (*(unsigned *)(_ISR_STARTADDRESS+0x68))
#define pISR_DMA2       (*(unsigned *)(_ISR_STARTADDRESS+0x6c))
#define pISR_DMA3       (*(unsigned *)(_ISR_STARTADDRESS+0x70))
#define pISR_SDI        (*(unsigned *)(_ISR_STARTADDRESS+0x74))
#define pISR_SPI0       (*(unsigned *)(_ISR_STARTADDRESS+0x78))
#define pISR_UART1      (*(unsigned *)(_ISR_STARTADDRESS+0x7c))
#define pISR_NFCON      (*(unsigned *)(_ISR_STARTADDRESS+0x80))     // Added for 2440.
#define pISR_USBD       (*(unsigned *)(_ISR_STARTADDRESS+0x84))
#define pISR_USBH       (*(unsigned *)(_ISR_STARTADDRESS+0x88))
#define pISR_IIC        (*(unsigned *)(_ISR_STARTADDRESS+0x8c))
#define pISR_UART0      (*(unsigned *)(_ISR_STARTADDRESS+0x90))
#define pISR_SPI1       (*(unsigned *)(_ISR_STARTADDRESS+0x94))
#define pISR_RTC        (*(unsigned *)(_ISR_STARTADDRESS+0x98))
#define pISR_ADC        (*(unsigned *)(_ISR_STARTADDRESS+0x9c))


// PENDING BIT
#define BIT_EINT0       (0x1)
#define BIT_EINT1       (0x1<<1)
#define BIT_EINT2       (0x1<<2)
#define BIT_EINT3       (0x1<<3)
#define BIT_EINT4_7     (0x1<<4)
#define BIT_EINT8_23    (0x1<<5)
#define BIT_CAM         (0x1<<6)        // Added for 2440.
#define BIT_BAT_FLT     (0x1<<7)
#define BIT_TICK        (0x1<<8)
#define BIT_WDT_AC97    (0x1<<9)    // Changed from BIT_WDT to BIT_WDT_AC97 for 2440A  
#define BIT_TIMER0      (0x1<<10)
#define BIT_TIMER1      (0x1<<11)
#define BIT_TIMER2      (0x1<<12)
#define BIT_TIMER3      (0x1<<13)
#define BIT_TIMER4      (0x1<<14)
#define BIT_UART2       (0x1<<15)
#define BIT_LCD         (0x1<<16)
#define BIT_DMA0        (0x1<<17)
#define BIT_DMA1        (0x1<<18)
#define BIT_DMA2        (0x1<<19)
#define BIT_DMA3        (0x1<<20)
#define BIT_SDI         (0x1<<21)
#define BIT_SPI0        (0x1<<22)
#define BIT_UART1       (0x1<<23)
#define BIT_NFCON       (0x1<<24)       // Added for 2440.
#define BIT_USBD        (0x1<<25)
#define BIT_USBH        (0x1<<26)
#define BIT_IIC         (0x1<<27)
#define BIT_UART0       (0x1<<28)
#define BIT_SPI1        (0x1<<29)
#define BIT_RTC         (0x1<<30)
#define BIT_ADC         (0x1<<31)
#define BIT_ALLMSK      (0xffffffff)

#define BIT_SUB_ALLMSK  (0x7fff)            //Changed from 0x7ff to 0x7fff for 2440A 
#define BIT_SUB_AC97    (0x1<<14)       //Added for 2440A 
#define BIT_SUB_WDT     (0x1<<13)       //Added for 2440A 
#define BIT_SUB_CAM_P   (0x1<<12)       // edited for 2440A.
#define BIT_SUB_CAM_C   (0x1<<11)       // edited for 2440A
#define BIT_SUB_ADC     (0x1<<10)
#define BIT_SUB_TC      (0x1<<9)
#define BIT_SUB_ERR2    (0x1<<8)
#define BIT_SUB_TXD2    (0x1<<7)
#define BIT_SUB_RXD2    (0x1<<6)
#define BIT_SUB_ERR1    (0x1<<5)
#define BIT_SUB_TXD1    (0x1<<4)
#define BIT_SUB_RXD1    (0x1<<3)
#define BIT_SUB_ERR0    (0x1<<2)
#define BIT_SUB_TXD0    (0x1<<1)
#define BIT_SUB_RXD0    (0x1<<0)


#define enable_irq_bit(bit)     rINTMSK &= ~(bit)
#define disable_irq_bit(bit)        rINTMSK |= (bit)
#define enable_sub_irq_bit(bit) rINTSUBMSK &= ~(bit)
#define disable_sub_irq_bit(bit)    rINTSUBMSK |= (bit)

typedef void (*irq_call_back)(unsigned int irq_nb);

void arch_request_irq(unsigned int irq, irq_call_back call_back);
void arch_clear_pending_sub_irq_bit(int bit);
void arch_clear_pending_irq_bit(int bit);

#endif
